This manual provides step-by-step documentation on how the Voucher Create Form works in
the system, specifically focusing on the _voucher_type combobox (dropdown), how it loads
data from the database, and the relevant codebase.
The Voucher Type dropdown is loaded with data originating from the database through the Controller and passed to the Blade View. The data fetching ensures that users can dynamically select from available voucher types like Cash Receive (CR), Cash Payment (CP), Bank Receive (BR), Bank Payment (BP), and Journal Voucher (JV).
The system uses the VoucherType model, which refers to the
voucher_types database table. This table contains the definitions (id, name, and code) of
all existing voucher types.
Though you mentioned `VoucherTypeController.php`, the primary logic fetching this data for the form resides in VoucherMasterController.php (inside the `create()` method).
Here is how the controller gets the data using the VoucherType model:
// In app/Http/Controllers/VoucherMasterController.php -> create()
public function create()
{
// Getting the currently authenticated user
$users = Auth::user();
// ...other related data fetches like branches, account groups, etc...
// Fecthing the Voucher Types from the Database
$voucher_types = VoucherType::select('id', '_name', '_code')
->orderBy('_code', 'asc')
->get();
// Passing the data to the view
return view('backend.voucher.create', compact(
// ...other variables...
'voucher_types'
));
}
The controller executes a query analogous to:
SELECT id, _name, _code FROM voucher_types ORDER BY _code ASC;
Location: resources/views/backend/voucher/create.blade.php (Often referred to as public/voucher/create.blade.php by front-end routing).
The variables passed from the Controller (such as $voucher_types) are then looped over using
Blade's @forelse directive to populate the select dropdown (combobox). Below is the exact
code snippet from the view:
<div class="form-group">
<label>Voucher Type: <span class="_required">*</span></label>
<select class="form-control _voucher_type" name="_voucher_type" required="true">
<option value="">--Voucher Type--</option>
@forelse($voucher_types as $voucher_type )
<option value="{{$voucher_type->_code}}"
@if(isset($request->_voucher_type))
@if($request->_voucher_type == $voucher_type->_code)
selected
@endif
@endif>
{{ $voucher_type->_name ?? '' }}
</option>
@empty
<!-- Fallback if no data is found -->
@endforelse
</select>
</div>
Explanation: The name="_voucher_type" attribute ensures that when the form
is submitted, the selected _code value (e.g., 'CR', 'CP') is sent as
_voucher_type to the VoucherMasterController::store() method.
| Component Type | Name / File Path | Description |
|---|---|---|
| Table | voucher_types |
Stores the available default voucher classifications (ID, Code, Name). |
| Table | voucher_masters |
The main table where the submitted voucher headers are saved. |
| Model | App\Models\VoucherType |
The Eloquent Model to interact with the voucher_types table. |
| Model | App\Models\VoucherMaster |
The Eloquent Model to interact with the voucher_masters table upon form
submission. |
| Controller | App\Http\Controllers\VoucherMasterController |
Handles fetching $voucher_types data and returning the view (in the
create() method). |
| View (Blade) | resources/views/backend/voucher/create.blade.php |
The user interface showcasing the form holding the _voucher_type combobox. |
VoucherMasterController@create is triggered.VoucherType::select(...) fetches valid voucher types from
the database.create.blade.php.@forelse loop iterates through the data and
renders the HTML <select> and <option> tags.